package com.dfd.producer.controller;

import com.dfd.common.po.ResponseVo;
import com.dfd.producer.service.MqProducerService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created on 2021/12/21.
 *
 * @author DD
 */
@Slf4j
@RestController
@RequestMapping("/mqProducer")
public class MqProducerController {
    @Autowired
    MqProducerService mqProducerService;


    /**
     * 发送简单的MQ消息
     *
     * @param msg
     * @return
     */
    @GetMapping("/send")
    public ResponseVo<SendResult> send(String msg) {
        SendResult sendResult = null;
        try {
            sendResult = mqProducerService.send(msg);
        } catch (Exception e) {
            return ResponseVo.error(e.getMessage());
        }
        return ResponseVo.success(sendResult);
    }
}
